#-*- coding:utf-8 -*-
import wda
import sys
import logging
from time import sleep
import logging.config
import element
import unittest

reload(sys)
sys.setdefaultencoding("utf8")
logging.config.fileConfig("logging.conf")
wda.DEBUG=False
class mytest(unittest.TestCase):

    def setUp(self):
        self.c = wda.Client(uuid="9e253b286ebb2411c955547c5eef451601bd37b1")
        self.s = self.c.session('com.yy.enterprise.yyliveworld')

    def tearDown(self):
        self.s.close()
        self.c.close()


    def testrun(self):
        self.s(xpath=element.XPATH_ENVIR_BTN).click()
        self.s(name=element.NAME_HOME_TAB).click()
        self.c.screenshot("test.png")
        for i in range(1, 200):
            logging.info(i)
            try:

                if self.s(name=element.NAME_PKHOME_LABEL).wait(5):
                    self.s.tap(100 + i % 2 * 200, 237 + round(i / 2) % 2 * 200);
                    sleep(3)
            except BaseException, e:
                print e
                logging.error("进入error")
            try:
                # s(xpath="//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeScrollView[1]/XCUIElementTypeOther[1]/XCUIElementTypeCollectionView[1]/XCUIElementTypeCell[3]/XCUIElementTypeOther[1]/XCUIElementTypeImage[1]").click();
                if self.s(name=element.NAME_PKVALUE_LABEL).wait(5):
                    self.s.tap(150, 150)
                    self.s.tap(329, 237)
            except:
                logging.error("退出error")

if __name__ == '__main__':
    unittest.main()